import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:get/get.dart';
import 'package:high_help_apps/common/values/colors.dart';
import 'package:high_help_apps/pages/main/home/life_help/help_each_other/help_each_other_view.dart';
import 'package:high_help_apps/pages/main/home/life_help/second_hand_market/second_hand_market_view.dart';

import 'life_help_logic.dart';
import 'life_help_state.dart';

/// 屏幕适配 百度 flutter_screenutil 可以出来教程, 作用是把单位统一, 使程序在不同机型上显示相同
/// 不会变形
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LifeHelpPage extends StatefulWidget {
  @override
  _LifeHelpPageState createState() => _LifeHelpPageState();
}

class _LifeHelpPageState extends State<LifeHelpPage> {
  final LifeHelpLogic logic = Get.put(LifeHelpLogic());
  final LifeHelpState state = Get.find<LifeHelpLogic>().state;

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: Text(
            "生活互助区",
            style: TextStyle(color: Colors.white),
          ),
          centerTitle: true,
          bottom: TabBar(
            tabs: <Widget>[Tab(text: "二手市场"), Tab(text: "互帮互助")],
            indicatorColor: Colors.white,
            labelColor: Colors.white,
            labelStyle: TextStyle(fontSize: 18.sp),
          ),
          shadowColor: Colors.transparent,
          elevation: 0.0,
          iconTheme: IconThemeData(color: Colors.white),
        ),
        floatingActionButton: SpeedDial(
            backgroundColor: AppColors.primaryElement,
            overlayColor: Colors.black54,
            tooltip: '生活互助菜单',
            elevation: 2.75,
            child: Icon(Icons.add),
            children: [
              SpeedDialChild(
                child: Icon(
                  Icons.add_shopping_cart,
                ),
                label: '发布二手商品',
                labelStyle: TextStyle(fontSize: 18.0),
                onTap: () {
                  logic.enterAddShop();
                },
              ),
              SpeedDialChild(
                  child: Icon(Icons.add_task),
                  label: '发布悬赏任务',
                  labelStyle: TextStyle(fontSize: 18.0),
                  onTap: () {
                    logic.enterReleaseReward();
                  }),
            ]),
        // floatingActionButton: FloatingActionButton(
        //   backgroundColor: AppColors.primaryElement,
        //   child: Icon(Icons.add),
        //
        //   /// 现在使用GetX来进行路由导航，不要用原生的
        //   /// 百度GetX出来路由教程
        //   /// 在logic里面写逻辑，这个view只负责UI页面，也就是显示的部分
        //   /// logic里面负责的是数据的处理
        //   /// 在当前文件同级找到logic结尾的文件
        //   onPressed: logic.showLifeHelpButtonMenu,
        // ),
        body: TabBarView(
          children: <Widget>[SecondHandMarketPage(), HelpEachOtherPage()],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<LifeHelpLogic>();
    super.dispose();
  }
}
